﻿using System.Collections.Generic;
using System.Text;
using Core.Domain;

namespace Core.SyntaxAnalysis.Classes
{
    public class Declrs
    {
        private static readonly Declrs c_empty = new Declrs();
        public List<Declaration> Declarations;

        private Declrs()
        {
            Declarations = new List<Declaration>();
        }

        public Declrs(List<Identificator> variables, DataType type)
        {
            Declarations = new List<Declaration> {new Declaration(variables, type)};
        }

        public void Append(Declaration next)
        {
            Declarations.Add(next);
        }

        public static Declrs EmptyDeclrs()
        {
            return c_empty;
        }

        public bool SemanticCheck(ref List<CompilerError> errors)
        {
            foreach (var current in Declarations)
            {
                if (!current.SemanticCheck(ref errors))
                {
                    return false;
                }
            }
            return true;
        }

        public void Generate(StringBuilder s)
        {
            foreach (var declr in Declarations)
            {
                declr.Generate(s);
            }
        }
    }
}